-- Ref Links: 
-- 01. http://stackoverflow.com/questions/679000/how-to-check-if-a-database-exists-in-sql-server
-- 02. http://stackoverflow.com/questions/727788/how-to-use-a-variable-for-the-database-name-in-t-sql

USE [master]
GO

DECLARE @dbName		VARCHAR(15);
SET		@dbName		= N'SGLDBMP01';

IF (
	EXISTS ( 
		SELECT	name
		FROM	master.dbo.sysdatabases
		WHERE	('[' + name + ']' = @dbName
			OR	name = @dbName)
			)
	)
	-- Condition satisfied database with this name already exists in this SQL Instance
	PRINT 'Database : ' + @dbName + ', already exists in this instance, please create with different name';
ELSE
	-- Database does not exits, create the database
	BEGIN
		DECLARE	@CREATE_TEMPLATE	VARCHAR(80);
		DECLARE @COMP_TEMPLATE		VARCHAR(80);
		DECLARE @RECOVER_TEMPLATE	VARCHAR(80);
		
		SET @CREATE_TEMPLATE	= 'CREATE DATABASE {dbName}';
		SET @COMP_TEMPLATE		= 'ALTER DATABASE {dbName} SET COMPATIBILITY_LEVEL = 100';
		SET @RECOVER_TEMPLATE	= 'ALTER DATABASE {dbName} SET RECOVERY SIMPLE';
		
		DECLARE @ExeSQL				VARCHAR(150);
		
		SET @ExeSQL				= REPLACE (@CREATE_TEMPLATE, '{dbName}', @dbName);
		EXECUTE (@ExeSQL);
		
		SET @ExeSQL				= REPLACE (@COMP_TEMPLATE, '{dbName}', @dbName);
		EXECUTE (@ExeSQL);
		
		SET @ExeSQL				= REPLACE (@RECOVER_TEMPLATE, '{dbName}', @dbName);
		EXECUTE (@ExeSQL);
		
		PRINT 'Database : ' + @dbName + ', created successfully with CompMode: 100 and RecMode: Simple';
	END

/*	Output (01): Database : SGLDBMP01, created successfully with CompMode: 100 and RecMode: Simple
	Output (02): Database : SGLDBMP01, already exists in this instance, please create with different name
*/	

-- Alternate option of creating a database using SQL CMD

/*
SET VAR dbName "SGLDBMP01"

CREATE DATABASE $(dbName)
GO

ALTER DATABASE $(dbName) SET COMPATIBILITY_LEVEL = 100
GO

ALTER DATABASE $(dbName) SET RECOVERY SIMPLE
GO
*/